<template>
	<view class="content">
		<scroll-view scroll-y class="left-aside">
			<view v-for="(item,finfex) in flist" :key="finfex" class="f-item b-b" :class="{active: currentId=== finfex}" @click="tabtap(finfex)">
				{{item.name}}
			</view>
		</scroll-view>
		<scroll-view scroll-with-animation scroll-y class="right-aside" >
			<view v-for="(item,ikey) in slist" :key="ikey" class="s-list" :id="'main-'+item.id">
				<text class="s-item">{{item.name}}</text>
				<view class="t-list">
					<view @click="navToList(titem.id,titem.name)" class="t-item" v-for="(titem,tkey) in item.items" :key="tkey">
						<view v-if="titem.icon !=''" class="empty">
							<image :src="titem.icon" style="width: 116upx;height: 110upx;background-color: #eee;" ></image>
						</view>
						<view v-else  class="empty">
							<image src="../../static/error.png" style="width: 116upx;height: 110upx;background-color: #eee;" ></image>
						</view>
						<text class="goodtitle">{{titem.name}}</text>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import postAjax from '../../API/postAjax.js'
	export default {
		data() {
			return {
				sizeCalcState: false,
				tabScrollTop: 0,
				currentId: 0,
				currentIndex:0,
				list:[],
				flist: [],
				slist: [],
			}
		},
		onLoad(){
			let that = this
			that.loadData();
		},
		methods: {
			async loadData(){
				let that = this
				let lists = await that.loadsort()
				lists.forEach(item=>{
					if(item.pid==0){
						that.flist.push(item);  //pid为父级id, 没有pid或者pid=0是一级分类
					}
				})
				that.slist = that.flist[that.currentIndex].items
			},
			 
			// 获取信息
			loadsort(){
				return new Promise((resolve, reject) => {
					uni.showLoading()
					postAjax('goods/Category',{pid:0}, function(data) {
						resolve(data.data)
						uni.hideLoading()
					})
					
				})
					
			},
			//一级分类点击
			tabtap(index){
				console.log(index)
				this.currentId = index
				this.slist = this.flist[index].items
			},
			navToList(sid,sname){
				uni.navigateTo({
					url: `/pages/hotfunc/sortgoods?id=${sid}&name=${sname}`
				})
			}
		}
	}
</script>

<style>
	page,
	.content {
		height: 100%;
		background-color: #f8f8f8;
	}

	.content {
		display: flex;
	}
	.left-aside {
		flex-shrink: 0;
		width: 200upx;
		height: 100%;
		background-color: #f9f9f9;
	}
	.goodtitle{overflow: hidden;white-space: nowrap;text-overflow: ellipsis;}
	.f-item {
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #f9f9f9;
		width: 100%;
		height: 100upx;
		font-size: 28upx;
		color: #666;
		position: relative;
	}
.active{
	background: #fff;
}
.active::before{
	content: '';
	position: absolute;
	left: 0;
	top: 0;
	/* transform: translateY(-50%); */
	height:100%;
	width: 8upx;
	background-color: #1D84E8;
	opacity: .8;
}
.right-aside{
	flex: 1;
	overflow: hidden;
	padding-left: 20upx;
	background-color: #fff;
}
.s-item{
	display: flex;
	align-items: center;
	height: 70upx;
	padding-top: 8upx;
	font-size: 28upx;
	color: #666;
}
.t-list{
	display: flex;
	flex-wrap: wrap;
	width: 100%;
	background: #fff;
	padding-top: 12upx;
}
.t-list::after{
	content: '';
	flex: 99;
	height: 0;
}
.t-item{
	flex-shrink: 0;
	display: flex;
	justify-content: center;
	align-items: center;
	flex-direction: column;
	width: 176upx;
	font-size: 26upx;
	color: #666;
	padding-bottom: 20upx;
}
img:after { 
  content: url('../../static/error.png');
  display: block;
  position: absolute;
   
  background-color: #fff;
 
}
</style>
